package cn.edu.zzuli.message.config;


import cn.edu.zzuli.common.constant.RabbitConstant;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMqConfig {

    /**
     * 声明direct交换机
     *
     * @return
     */
    @Bean
    DirectExchange directExchange() {
        return new DirectExchange(RabbitConstant.EXCHANGE);
    }
 
    /**
     * 声明队列
     *
     * @return
     */
    @Bean
    public Queue queueTakeOrder() {
        // true表示持久化该队列
        return new Queue(RabbitConstant.QUEUE_TAKE_ORDER, true);
    }
 
    @Bean
    public Queue queueCancelOrder() {
        // true表示持久化该队列
        return new Queue(RabbitConstant.QUEUE_CANCEL_ORDER, true);
    }
 
    @Bean
    public Queue queueApplyOrder() {
        // true表示持久化该队列
        return new Queue(RabbitConstant.QUEUE_APPLY_ORDER, true);
    }

    @Bean
    public Queue queueBroadcastMessages() {
        // true表示持久化该队列
        return new Queue(RabbitConstant.QUEUE_BROADCAST_MESSAGES, true);
    }

    @Bean
    public Queue queuesSignIn() {
        // true表示持久化该队列
        return new Queue(RabbitConstant.QUEUE_SIGN_IN, true);
    }

    @Bean
    public Queue queuesChat() {
        // true表示持久化该队列
        return new Queue(RabbitConstant.QUEUE_USER_CHAT, true);
    }

 
    /**
     * 绑定
     *  接单信息
     * @return
     */
    @Bean
    public Binding bindingTakeOrder() {
        return BindingBuilder.bind(queueTakeOrder()).to(directExchange()).with(RabbitConstant.ROUTING_KEY_TAKE_ORDER);
    }
 
    /**
     * 绑定
     * 取消信息
     * @return
     */
    @Bean
    public Binding bindingCancelOrder() {
        return BindingBuilder.bind(queueCancelOrder()).to(directExchange()).with(RabbitConstant.ROUTING_KEY_CANCEL_ORDER);
    }
 
    /**
     * 绑定
     *  申请信息
     * @return
     */
    @Bean
    public Binding bindingApplyOrder() {
        return BindingBuilder.bind(queueApplyOrder()).to(directExchange()).with(RabbitConstant.ROUTING_KEY_APPLY_ORDER);
    }

    /**
     * 绑定
     *  超时订单
     * @return
     */
    @Bean
    public Binding bindingOvertimeOrder() {
        return BindingBuilder.bind(queueBroadcastMessages()).to(directExchange()).with(RabbitConstant.ROUTING_KEY_BROADCAST_MESSAGES);
    }

    /**
     * 签到
     * @return
     */
    @Bean
    public Binding bindingSignIn() {
        return BindingBuilder.bind(queuesSignIn()).to(directExchange()).with(RabbitConstant.QUEUE_SIGN_IN);
    }

    /**
     *  消息通知
     * @return
     */
    @Bean
    public Binding bindingChat() {
        return BindingBuilder.bind(queuesChat()).to(directExchange()).with(RabbitConstant.QUEUE_USER_CHAT);
    }
 
}